package com.klhappy.houyuan.activity;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

import com.google.gson.Gson;
import com.klhappy.houyuan.bean.BaseJsonBean;
import com.klhappy.houyuan.bean.FoodStampBean.StampBean;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.interfaces.CallBackInterModle;
import com.klhappy.houyuan.modle.JiaYuanModle;
import com.klhappy.houyuan.utils.JsonCode;
import com.klhappy.houyuan.view.AbsActivity;
import com.klhappy.houyuan.R;
import com.klhappy.houyuan.adapter.FoodStampAdapter;
import com.klhappy.houyuan.bean.FoodsStamp.FoodStampBean;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

public class Food_StampActivity extends AbsActivity implements CallBackInterModle {
	public static final String ADG = "Food_StampActivity";
	@InjectView(R.id.food_stamp_list)
	ListView food_stamp_list;
	@InjectView(R.id.title)
	TextView title;
	@InjectView(R.id.right_text)
	TextView right_text;

	@OnClick(R.id.click_ra)
	public void click_ra(){
		finish();
	}

	@OnClick(R.id.click_li)
	public void click_li(){
		startActivity(new Intent(this, Stamp_RuleActivity.class));
	}

	private JiaYuanModle modle;
	private FoodStampAdapter adapter;
	private FoodStampBean stampBean;
	private List<StampBean> stampBeans;

	private boolean flag;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.food_stamp);
		ButterKnife.inject(this);
		intView();

		flag = getIntent().getBooleanExtra("flag" ,true);
		modle = new JiaYuanModle(this);
		modle.setCallBackInterModle(this);
		modle.getStamp();
		showDialog("请稍等...");
	}

	private void intView(){
		title.setText(R.string.food_stamp);
		right_text.setVisibility(View.VISIBLE);
		right_text.setText(R.string.food_result);
	}

	@Override
	public void CallBackFromModle(String url, BaseJsonBean o) {
		if (url.equals(UrlConstant.STAMP_URL)){
			if (o.getCode() == 200){
				Gson gson = new Gson();
				Log.e("this" ,gson.toJson(o));
				stampBean = JsonCode.getClass(o.getEntity() ,FoodStampBean.class);
				stampBeans = JsonCode.getClassList(stampBean.getRecords() ,StampBean.class);
				try {
					adapter = new FoodStampAdapter(this, stampBeans);
					food_stamp_list.setAdapter(adapter);
				}catch (Exception e){

				}
			}
			closeDialog();
		}
	}
}
